package com.example.designpattern.behavioral.strategy.factory;

import com.example.designpattern.behavioral.strategy.strategy.BubbleSort;
import com.example.designpattern.behavioral.strategy.strategy.ISort;
import com.example.designpattern.behavioral.strategy.strategy.InsertSort;
import com.example.designpattern.behavioral.strategy.strategy.SelectionSort;

/**
 * 简单工厂
 */
public class StrategyFactory implements IFacroty {
    @Override
    public ISort createStrategy(SortStrategy strategy) {
        ISort sort;
        switch (strategy) {
            case BUBBLE_SORT:
                sort = new BubbleSort();
                break;
            case SELECTION_SORT:
                sort = new SelectionSort();
                break;
            case INSERT_SORT:
                sort = new InsertSort();
                break;
            default:
                throw new IllegalArgumentException("There's no such strategy yet.");
        }
        return sort;
    }
}
